//用户信息接口
import axios from "../utils/axios";

//登录接口
export function login(username, password) {
    return axios({
        url: "/user/login",
        method: "POST",
        params: {username: username, password: password},
    });
}

//注册接口
export function register(username, password) {
    return axios({
        url: "/user/register",
        method: "POST",
        params: {username: username, password: password},
    });
}

//查看所有用户
export function lookAllUser() {
    return axios.get("/user");
}

//查看当前用户
export function lookCurrentUser(userId) {
    return axios.get(`/user/cu/${userId}`);
}

//根据角色查询用户
export function lookUserByRole(role) {
    return axios.get(`/user/role/${role}`);
}

//修改当前用户信息
export function updateCurrentUser(user) {
    return axios.put("/user", user);
}

//批量删除用户
export function deleteUsers(userIds) {
    return axios({url: "/user", method: "DELETE", data: userIds});
}

//用户头像上传
export function uploadAvatar(file, id) {
    return axios({
        url: "/user/loadAvatar",
        method: "POST",
        data: file,
        params: {id: id},
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
}

//头像下载
export function downloadAvatar(id) {
    return axios({
        url: "/user/downAvatar",
        method: "GET",
        responseType: "blob",
        params: {
            id: id,
        },
        headers: {
            Accept: "application/octet-stream",
        },
    });
}
